package cn.lanqiao.facelogin.BaiDuFace;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 人脸检测 示例代码
public class RequestDemo {
    public static void main(String[] args) {
        String path = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        // 设置query参数
        request.addQueryParameter("access_token", "24.750b2f571e4af9eca11b0374990c541f.2592000.1648168655.282335-25549431");

        // 设置jsonBody参数
        String jsonBody = "{\"image\":\"15151561654654\",\"image_type\":\"BASE64\"}";
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static String m1(String base64){
        String path = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        // 设置query参数
        request.addQueryParameter("access_token", "24.edba0e7585cba09796f6a10c3520a7e7.2592000.1645514920.282335-25549431");

        // 设置jsonBody参数
        String jsonBody = "{\"image\":\"+"+base64+"+\",\"image_type\":\"BASE64\"}";
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "response";
    }
}